package com.wondertek.poms.pre.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.wondertek.poms.common.constant.Constants;

/**
 * <p><b>RabbitmqConfig Description:</b> rabbitmq配置</p>
 * @author douzi
 * <b>DATE</b> 2020年12月10日 上午10:03:03
 */
@Configuration
public class RabbitmqConfig {

	@Bean
    public Queue contentQueue() {
        return new Queue(Constants.QUEUE_SYNC_CONTENT);
    }

    @Bean
    public Queue pomsNewQueue() {
        return new Queue(Constants.QUEUE_NEW_POMS_SYNC);
    }

    @Bean
    public Queue transImgQueue() {
        return new Queue(Constants.QUEUE_TRANS_IMG);
    }

    @Bean
    public Queue publishQueue() {
        return new Queue(Constants.QUEUE_SYNC_PUBLISH);
    }

    @Bean
    Queue delayQueue() {
        return new Queue(Constants.QUEUE_SLOW_SYNC_CONTENT);
    }
    
    @Bean
    Queue imgQueue() {
    	return new Queue(Constants.QUEUE_TRANS_IMG_BACK);
    }

    @Bean
    public Queue demoDelayQueueDeadLetterQueue() {
        return QueueBuilder
                .durable(Constants.POMS_DEAD_LETTER_QUEUE)
                .withArgument("x-dead-letter-exchange", Constants.POMS_DELAY_QUEUE)
                .withArgument("x-dead-letter-routing-key", Constants.POMS_DELAY_QUEUE)
                .withArgument("x-message-ttl", Constants.DELAY_QUEUE_TTL)
                .build();
    }

    @Bean
    public Queue demoDelayQueueOutputQueue() {
	    return QueueBuilder
                .durable(Constants.POMS_DELAY_QUEUE)
                .build();
    }

    @Bean
    public Exchange demoDelayQueueDeadLetterExchange() {
        return ExchangeBuilder
                .directExchange(Constants.POMS_DELAY_QUEUE)
                .build();
    }

    @Bean
    public Binding delayQueueDemoBinding() {
	    return BindingBuilder
                .bind(demoDelayQueueOutputQueue())
                .to(demoDelayQueueDeadLetterExchange())
                .with(Constants.POMS_DELAY_QUEUE)
                .noargs();
    }
}
